package com.zhengjiang.sms.consumer.configure;

import com.zhengjiang.sms.consumer.service.ISendSmsService;
import com.zhengjiang.sms.consumer.service.SendSmsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName SendMsgConfiguration
 * @Description
 * @Author zhengjiang(99514925 @ qq.com)
 * @Date 2020-05-28 10:13
 * @Version V1.0
 **/
@Configuration
@ConditionalOnClass(ISendSmsService.class)
@EnableConfigurationProperties(SendSmsProperties.class)
public class SendSmsAutoConfiguration {

    @Autowired
    SendSmsProperties sendSmsProperties;

    @Bean
    @ConditionalOnMissingBean(ISendSmsService.class)
    @ConditionalOnProperty(prefix = "sendSms",value = "enabled",havingValue = "true")
    public ISendSmsService sendSmsService(){
       return new SendSmsServiceImpl(sendSmsProperties);
    }
}
